package com.taldh.netty.server;

import com.taldh.netty.common.util.Logger;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * date 2020/7/16
 *
 * @author 袁小黑
 * @version 1.0.0
 **/

public class NettyEchoServerT {

    public static void main(String[] args) throws InterruptedException {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors());
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup, workGroup);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.bind("127.0.0.1",8000);
        serverBootstrap.option(ChannelOption.SO_BACKLOG, 1024)
                    .option(ChannelOption.SO_KEEPALIVE, true)
                    .childOption(ChannelOption.SO_BACKLOG, 1024)
        ;


        ChannelFuture future = serverBootstrap.bind().sync();
        Logger.info(" 服务器启动成功，监听端口: " + future.channel().localAddress());

        future.channel().close().sync();
    }

}
